#!/bin/bash

set -e

SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"

cd "$SCRIPT_DIR" || exit 1

if ! which php >/dev/null; then
	echo "PHP is required."
	exit 0
fi

if ! which composer >/dev/null; then
	echo "composer is required."
	exit 0
fi

if ! [[ -f $SCRIPT_DIR/composer.lock ]]; then
	composer install
else
	composer update
fi

echo "Running PHP client"

COMPILED_PATH=${COMPILED_GRPC_SO:-grpc}

php -d extension="${COMPILED_PATH}" -d max_execution_time=300 BentoServiceClient.php
